package demo2;




class Shape {
    //属性....
    public void draw() {
        System.out.println("画图形！");
    }
}

class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("♦！");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("●！");
    }
}

class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("❀！");
    }
}


class Triangle extends Shape {
    @Override
    public void draw() {
        System.out.println("△！");
    }
}

public class Test {

    /*public static void drawMap(Shape shape) {
        shape.draw();
    }*/

    public static void main(String[] args) {
        /*Shape shape1 = new Rect();
        Shape shape2 = new Cycle();
        Shape shape3 = new Flower();

        Shape[] shapes = {shape1,shape2,shape1,shape2,shape3};*/

        //创建了一个 Shape 对象的数组
        Shape[] shapes = {new Rect(),new Cycle(),new Rect(),new Cycle(),new Flower()};

        for (Shape shape: shapes) {
            shape.draw();
        }
    }



    public static void main1(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        String[] strings = {"rect","cycle","rect","cycle","flower"};

        for (String x: strings) {
            if(x.equals("rect")) {
                rect.draw();
            } else if(x.equals("cycle")) {
                cycle.draw();
            } else if(x.equals("flower")) {
                flower.draw();
            }
        }
    }
}
